#
#copyright (C) 2017-2030 TW
#
#by Bob@TW@18:02-2017-09-13.
#

MODULE = mu

RELATIVE_PATH = $(subst $(MUDP_TOP_DIR)/,,$(shell pwd))

.PHONY: all prepare menuconfig build install rootfs clean 

ifeq ($(MODULE),xxx-0.0.0)
all: 
	@echo $(MODULE) is templete module.
else
ifneq ($(shell find ./ -mmin -$(MUDP_INTERVAL_COMPILE_TIME) -mmin +0 -cmin -$(MUDP_INTERVAL_COMPILE_TIME) -cmin +0),)
all: clean prepare build install rootfs
	@echo building of $(MODULE) is complete.
else
all: 
	@echo nothing to do with building of $(MODULE).
endif
endif

prepare:
	echo nothing to do.

menuconfig:
	echo nothing to do.

build: mu_lib mu_main
	echo nothing to do.

install:
	cp $(MUDP_BUILD_DIR)/mu/mu $(MUDP_ROOTFS_DIR)/sbin -rf

rootfs:
	cp $(MUDP_BUILD_DIR)/mu/mu $(MUDP_INSTALL_DIR)/sbin -rf
	
clean:
	rm -rf $(MUDP_BUILD_DIR)/$(MODULE)

#
#make libmu shared library.
#
mu_lib: 
	make -C lib

# 
#objs include the necessary directories and the source files   
#
EXECU_SUB_DIRS = main
EXECU_ALL_OBJS = $(addprefix $(MUDP_BUILD_DIR)/mu/, $(addsuffix .o, $(EXECU_SUB_DIRS))) 

INCLUDE += -I$(MU_MU_DIR)/include

ifeq ($(CONFIG_MU_TARGET_VERSION_TYPE_RELEASE),y)
CFLAGS  += -DCONFIG_MU_TARGET_VERSION_TYPE_RELEASE
else
CFLAGS  += -DCONFIG_MU_TARGET_VERSION_TYPE_DEBUG
endif
LDFLAGS += -lmu -llua -lfcgi -ljson-c -lubox -lubus -lblobmsg_json

#
#make executive file.
#
mu_main: $(EXECU_ALL_OBJS)
	echo Build mu start...
	$(CXX)  $(LDFLAGS) $(CFLAGS) $(EXECU_ALL_OBJS) -o $(MUDP_BUILD_DIR)/mu/mu
	echo Done!!!

$(EXECU_ALL_OBJS): $(EXECU_SUB_DIRS)
	make -C $(EXECU_SUB_DIRS)

